<?php
	
require_once("nusoap/nusoap.php");
require_once("nusoap/class.wsdlcache.php");

function createProxy ($soap_url) {

	if (isset($_SESSION["sugar_soap_proxy"])) {
		unset($_SESSION["sugar_soap_proxy"]);
	}
    $cache = new nusoap_wsdlcache('/tmp', 86400);
    $wsdl = $cache->get($soap_url);
    if (is_null($wsdl)) {
      $wsdl = new wsdl($soap_url, '', '', '', '', 5);
      $cache->put($wsdl);
    }
	$soapclient = new nusoap_client($wsdl,'wsdl');
               $proxy = $soapclient->getProxy();
	$_SESSION["sugar_soap_proxy"] = $proxy;


        return $proxy;
}

function getProxy ($soap_url) {
	
	if (isset($_SESSION["sugar_soap_proxy"])) {
		return $_SESSION["sugar_soap_proxy"];
	} else {
		return createProxy($soap_url);
	}
		
}
		
?>
